package com;

import org.apache.commons.lang3.ArrayUtils;

import com.sojoys.artifact.factory.bytebuff.IByteBuff;
import com.sojoys.artifact.factory.bytebuff.IByteBuffFactory;
import com.sojoys.artifact.factory.bytebuff.NettyByteBuffFactory;

import sun.misc.Contended;

/**
 * @author : DengYing
 * @CreateDate : 2017年9月4日 下午5:46:46
 * @Description ：Please describe this document
 */
@Contended
public class Test {
	public static void main(String[] args) {
		IByteBuffFactory factory = new NettyByteBuffFactory();
		
//		IByteBuffFactory factory = new ArrayByteBuffFactory();
		IByteBuff buff = factory.allocate();
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < 20; i++) {
			sb.append(i);
			System.out.println(sb.toString());
			buff.writeString(sb.toString());
		}
		System.out.println("");
		byte[] data = buff.toByte();
		System.out.println(ArrayUtils.toString(data));
		IByteBuff buff2 = factory.wrap(data);
		
		for (int i = 0; i < 20; i++) {
			System.out.println(buff2.readString(null));	
		}
	}
}
